package com.demo.designmode.strategy.case2;

import com.demo.designmode.strategy.case1.PayService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/xiaoniu")
public class PayController {

    /**
    * 支付接口
    * @param channel 渠道
    * @param amount  消费金额
    * @return String 返回消费结果
    * @author Ye hongzhi
    * @date 2020/4/5
    */
    @RequestMapping("/pay")
    public String pay(@RequestParam(name = "channel") String channel,
                      @RequestParam(name = "amount") String amount)throws Exception{
        PayStrategy payStrategy = PayStrategyFactory.getPayStrategy(channel);
        if(payStrategy == null){
            return "输入渠道码有误";
        }
        return payStrategy.pay(channel,amount);
    }
}